package com.scau.ums.service.imp.info;

import com.scau.ums.model.Info;
import com.scau.ums.model.Maintainer;
import com.scau.ums.model.Student;
import com.scau.ums.model.Teacher;
import com.scau.ums.service.imp.userInfo.MaintainerInfoImp;
import com.scau.ums.service.imp.userInfo.StudentInfoImp;
import com.scau.ums.service.imp.userInfo.TeacherInfoImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * author: 莫伟杰
 * date： 2019/8/2 15:37
 */
@Service
@EnableAsync
public class AllUserSendInfoImp extends SendInfoImp {

    private StudentInfoImp studentInfoImp;
    private TeacherInfoImp teacherInfoImp;
    private MaintainerInfoImp maintainerInfoImp;

    @Autowired
    public void setStudentInfoImp(StudentInfoImp studentInfoImp) {
        this.studentInfoImp = studentInfoImp;
    }

    @Autowired
    public void setTeacherInfoImp(TeacherInfoImp teacherInfoImp) {
        this.teacherInfoImp = teacherInfoImp;
    }

    @Autowired
    public void setMaintainerInfoImp(MaintainerInfoImp maintainerInfoImp) {
        this.maintainerInfoImp = maintainerInfoImp;
    }

    //重载createInfoList方法，参数（标题，发送者ID，发送内容），默认发送除管理员外全部用户
    public List<Info> createInfoList(String title, String sendId, String content)
    {
        List<Info> infos = new ArrayList<>();
        //对每个学生/老师/维修工分别装填info
        List<Student> students = studentInfoImp.getAllUsers();
        for (Student s:students) {
            infos.add(createInfo(title,sendId,s.getId(),"学生",content));
        }
        List<Teacher> teachers = teacherInfoImp.getAllUsers();
        for (Teacher t:teachers) {
            infos.add(createInfo(title,sendId,"老师",t.getId(),content));
        }
        List<Maintainer> maintainers = maintainerInfoImp.getAllUsers();
        for (Maintainer m:maintainers) {
            infos.add(createInfo(title,sendId,m.getId(),"维修工",content));
        }
        return infos;
    }
}
